package itheima.com.socketdemo2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //找码头 ---------表示接收端从10000端口接收数据的
        DatagramSocket ds = new DatagramSocket(10000);
        //创建一个新的箱子
        byte[] bytes = new byte[1024];
        //接收礼物，把礼物放到新箱子中
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        System.out.println("-----接受前------");
        ds.receive(dp);
        System.out.println("-----接受后------");
        //从新的箱子获取礼物
     /*   byte[] data = dp.getData();
     int length = dp.getLength();
        System.out.println(new String(data,0,length));*/
        int length = dp.getLength();
        System.out.println(new String(bytes, 0, length));
        //拿完关闭走人
        ds.close();
    }
}
